<?php 

include('navigation.php');
// $autoreply_m=new M('autoreply');
// $autoreplylist=$autoreply_m->select('1');
// $autoreplymap=array();
// foreach($autoreplylist as $k=>$v){
//     $autoreplymap[$v['message']]=$v;
// }
// echo var_export($autoreplymap['测试']);
?>

<!-- End Navigation -->

<div class="container main-content">
    <!-- DataTables Example -->
    <div class="row">
        <div class="col-lg-12">
            <div class="widget-container fluid-height clearfix">
                <div class="heading">
                    <i class="se7en-flag"></i>　自动回复管理
                </div>
                <form id="autoreplyform" action="shenhe.do.php?do=set_autoreply" method="post" enctype="multipart/form-data" data-step="1" data-intro="设置自动回复信息，用户发送触发文字后，微信公众号返回给用户一个预设好的图片信息。">
                <div class="widget-content padded form-horizontal">
                    <div class="form-group" >
                        <label class="control-label col-md-2">触发文字:</label>
       
                                <div class="input-group  col-md-10">
                                    <input class="form-control" value="" name="message"
                                           type="text"/>
                                </div>
           
                      </div>
                      <div class="form-group">
                        <label class="control-label col-md-2">标题:</label>
   
                               <div class="input-group  col-md-10">
                                    <input class="form-control" value="" name="title" 
                                           type="text"/>
                                </div>
      
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2">描述:</label>


                                <div class="input-group  col-md-10">
                                    <input class="form-control" value="" name="description"
                                           type="text"/>
                                </div>

                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2">链接:</label>
                                <div class="input-group  col-md-10">
                                    <input class="form-control" value="" name="url" 
                                           type="text"/>
                                </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-md-2">图片:</label>
                        <div class="input-group  col-md-10">
                                <div class="fileupload fileupload-new" data-provides="fileupload">
                                    <div class="fileupload-preview fileupload-exists img-thumbnail"
                                         style="width: 455px; height: 135px;"></div>
                                    <div>
                                      <span class="btn btn-default btn-file"><span class="fileupload-new">选择图片</span>
                                      <input name="picurl" type="file"></span>
                                    </div>
                                </div>
                    </div>
                  </div>
                    <div class="row">
                        <label class="control-label col-md-2"></label>

                        <div class="col-md-3">
                            <button class="btn btn btn-block btn-primary-outline"
                                    onclick="saveautoreply();"
                                    id="tooltip-top">保存
                            </button>
                        </div>
                        
                    </div>
                </div>
                </form>
            </div>
        </div>
    </div>
    <!-- end DataTables Example -->
    
<div class="row">
        <div class="col-lg-12">
            <div class="widget-container fluid-height clearfix">
              <div class="heading">
                <i class="icon-table"></i>触发信息列表
              </div>
              <div class="widget-content padded clearfix" data-step="2" data-intro="已经设置好的自动回复信息列表。">
                <table class="table table-striped"  id="datatable-shady">
                  <thead>
                    <tr>
                    <th class="hidden-xs">
                      序号
                    </th>
                    <th>
                      关键字
                    </th>
                    <th>
                      标题
                    </th>
                    <th>
                      描述
                    </th>
                    <th>
                      连接
                    </th>
                    <th>
                      图片
                    </th>
                    <th>操作</th>
                  </tr></thead>
                  <tbody>
                    <?php
                    $autoreply_m=new M('autoreply');
                    $data=$autoreply_m->select('1');
                        foreach($data as $item)
                    {
                    ?>
                    <tr id="row_<?php echo $item['id']; ?>">
                      <td class="hidden-xs"><?php echo $item['id']; ?></td>
                      <td>
                        <?php echo $item['message']; ?>
                      </td>
                      <td>
                        <?php echo $item['title']; ?>
                      </td>
                      <td>
                        <?php echo $item['description']; ?>
                      </td>
                      <td>
                          <?php echo $item['url']; ?>
                      </td>
                      <td>
                          <img src='<?php echo $item['picurl'] ?>' style="width:100px;height:100px;" alt="<?php echo $item['title']; ?>"/>
                      </td>
                      <td><a href="javascript:del(<?php echo $item['id']; ?>)">删除</a></td>
                    </tr>
                     <?php }?>
                    
                  </tbody>
                </table>
              </div>
            </div>
        </div>
    </div>
</div>
</div>
<script type="text/javascript">
function saveautoreply(){
  $('#autoreplyform').submit();
}
function del(id){
  if(!confirm("确认要删除吗？"))return false;
  $.ajax({
    'url':'/myadmin/shenhe.do.php?do=del_autoreply',
    'type':'post',
    'data':{"id":id},
    'success':function(response){
      if(response>0){
        $('#row_'+id).remove();
      }else{ 
        alert('删除失败');
      }
    }
  });
}
    function showhelp(){
        console.log('show help sysset');
        introJs().setOptions({
                //对应的按钮
                prevLabel:"上一步", 
                nextLabel:"下一步",
                skipLabel:"跳过",
                doneLabel:"结束"
            }).start();
    }
</script>
</body>

</html>